package com.bskj.kuaifu.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bskj.common.bean.model.UserInvoice;
import com.bskj.common.dao.ParkInfoDao;
import com.bskj.common.dao.UserInvoiceDao;
import com.bskj.common.dao.core.BaseDao;
import com.bskj.common.dao.core.FindRequestEntity;
import com.bskj.common.dao.core.OrderEnum;
import com.bskj.common.dao.core.WhereEnum;
import com.bskj.common.service.impl.BaseServiceImpl;
import com.bskj.common.utils.DateTimeUtil;
import com.bskj.kuaifu.bean.vo.resp.UserInvoiceVo;
import com.bskj.kuaifu.service.IUserInvoiceService;

@Service
public class UserInvoiceServiceImpl extends BaseServiceImpl<UserInvoice> implements IUserInvoiceService{
	
	@Autowired
	private UserInvoiceDao userInvoiceDao;
	
	@Autowired
	private ParkInfoDao parkInfoDao;

	@Override
	public BaseDao<UserInvoice> getBaseDao() {
		
		return userInvoiceDao;
	}

	@Override
	public UserInvoiceVo FindInvMoney(Integer userId) throws Exception {
		UserInvoiceVo userInvoiceVo=new UserInvoiceVo();
		FindRequestEntity findReq=new FindRequestEntity();
		findReq.addWhere("user_id", WhereEnum.EQ, userId);
		findReq.addOrder("create_time", OrderEnum.DESC);
		List<UserInvoice> userInvoices=userInvoiceDao.find(findReq);
		if(userInvoices!=null&&userInvoices.size()>0){
			userInvoiceVo.setLastTime(DateTimeUtil.date2String(userInvoices.get(0).getCreateTime(),"yyyy-MM-dd"));
			userInvoiceVo.setLastMoney(userInvoices.get(0).getMoney());
			userInvoiceVo.setNowTime(DateTimeUtil.date2String(new Date(),"yyyy-MM-dd"));
			userInvoiceVo.setMoney(parkInfoDao.getInoviceCharge(DateTimeUtil.date2String(userInvoices.get(0).getCreateTime()), userId));
		}else {
			userInvoiceVo.setLastMoney(0);
			userInvoiceVo.setNowTime(DateTimeUtil.date2String(new Date(),"yyyy-MM-dd"));
			userInvoiceVo.setMoney(parkInfoDao.getInoviceCharge(null, userId));
		}
		return userInvoiceVo;
	}

}
